﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Evpo.ContactData.UI
{
    public partial class DatePicker : System.Web.UI.UserControl
    {
        public DatePicker()
        {
            MaximumValue = DateTime.MaxValue;
        }

        #region Fields
        #endregion Fields

        #region Properties

        public DateTime MaximumValue
        {
            get;
            set;
        }

        public DateTime? Date
        {
            get
            {
                if (String.IsNullOrEmpty(uiDate.Text))
                    return null;

                return DateTime.Parse(uiDate.Text);
            }
            set
            {
                if (!value.HasValue)
                    uiDate.Text = null;
                else
                    uiDate.Text = value.Value.ToShortDateString();
            }
        }

        public bool IsReadOnly
        {
            get;
            set;
        }

        public string RequiredErrorMessage
        {
            get;
            set;
        }

        public string RangeErrorMessage
        {
            get;
            set;
        }

        public bool IsRequired
        {
            get
            {
                return uiDateRequiredValidator.Enabled;
            }
            set
            {
                uiDateRequiredValidator.Enabled = value;
            }
        }
        #endregion Properties

        #region Handlers

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                uiDate.DataBind();
            }
            else
            {
                if(String.IsNullOrEmpty(uiDateValidator.MaximumValue))
                    uiDateValidator.MaximumValue = MaximumValue.ToShortDateString();
            }
        }

        #endregion Handlers


        #region Methods

        #endregion Methods

        #region Events
        #endregion Events
    }
}